package com.laowang.project.pay.config;


import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 微信公众号配置
 */

/**
 * @Auther laowang
 * @Date 2021/5/28
 * @Description
 */
@Configuration
public class WxConfigMy {

  /*@Autowired
  private WeixinOpen weixinOpen;
*/
  /**
   * 声明实例
   * @return
   */
  @Bean
  public WxMpService wxMpService() {

    WxMpService wxMpService = new WxMpServiceImpl();
    wxMpService.setWxMpConfigStorage(wxMpConfigStorage());
    return wxMpService;
  }

  /**
   * 微信客户端配置存储
   * @return
   */
  @Bean
  public WxMpConfigStorage wxMpConfigStorage() {
    WxMpDefaultConfigImpl configStorage = new WxMpDefaultConfigImpl();
    // 公众号appId
    configStorage.setAppId(WeixinOpenNew.appId);
    // 公众号appSecret
    configStorage.setSecret(WeixinOpenNew.secret);
    // 公众号Token
    configStorage.setToken(WeixinOpenNew.token);
    // 公众号EncodingAESKey
    configStorage.setAesKey(WeixinOpenNew.aesKey);
    return configStorage;
  }
}
